import csv
import json
import pandas as pd


# 获取时间
# def get_date_list():

# 读取json文件，以字典形式保存
def json_to_dict(path):
    with open(path, 'r') as f:
        dict = json.load(f)
    return dict


# 读取csv文件第3列(data列，第2列是采样间隔)
def get_data_list(path):
    data_list = []
    with open(path, 'r') as f:
        f_csv = csv.reader(f)
        for row in f_csv:
            data_list.append(row[2])

    return data_list


# pandas读取csv
def pd_get_data_list(path):
    df = pd.read_csv(path,header=0)
    print(df.head(5))

if __name__ == '__main__':
    path = 'jsonfile.json'
    sensor_list = ['cegun', 'chilunxiang', 'dianjichui', 'dianjiheng', 'fuchen', 'hengjian', 'hengxiang', 'lingxing',
                   'niuzhuan', 'qianyin', 'zhidong', '角速度', '_速度']
    dict_file = json_to_dict(path)
    data_list = get_data_list(dict_file['cegun'][0])
    print(data_list[0])
    print(len(data_list))


    # pandas读取csv练习
    df = pd.read_csv(dict_file['cegun'][0], header=0)
    # print(df.head(1))
    # print(len(df))
    print(df.head(100))